package com.difsonapps.contacttranslator.dao;

import org.hibernate.SessionFactory;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.difsonapps.contacttranslator.dto.NumberDTO;

@Repository
@Transactional
public class NumberDAO {
	@Autowired
	protected SessionFactory sessionFactory;

	@Transactional
	public void insert(NumberDTO numberDTO) {
		sessionFactory.getCurrentSession().save(numberDTO);
	}

	@Transactional
	public void update(NumberDTO numberDTO) {
		sessionFactory.getCurrentSession().update(numberDTO);
	}

	@Transactional
	public NumberDTO get(int id) {
		return (NumberDTO) sessionFactory.getCurrentSession().get(
				NumberDTO.class, id);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public List<NumberDTO> getAll() {
		return (List<NumberDTO>) sessionFactory.getCurrentSession()
				.createQuery("Select t from NumberDTO t").list();
	}

	@Transactional
	public void delete(NumberDTO numberDTO) {
		sessionFactory.getCurrentSession().delete(numberDTO);
	}
}
